//package com.miracle.erp.servlet;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.List;
//
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.fileupload.FileItem;
//import org.apache.commons.fileupload.FileItemFactory;
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
//
//import service.IUserService;
//import service.Impl.UserService;
//import util.AjaxObj;
//import util.ERPException;
//import util.ObjectFactory;
//import model.User;
//
//@WebServlet("/uploadLogin")
//public class UploadLoginServlet extends HttpServlet{
//	/**
//	 * 向后端传输用户输入的信息 封装
//	 */
//	/**
//	 * 发布图书,图片上传
//	 *
//	 * @param req
//	 * @param resp
//	 * @throws ServletException
//	 * @throws IOException
//	 */
//	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//		System.out.println("已进入sbmitBook");
//		String username = null;
//		String password = null;
//		String imgPath = null;
//		// 1 先判断上传的数据是否多段数据（只有是多段的数据，才是文件上传的）
//		if (isMultipartContent(req)) {
//			// 创建FileItemFactory工厂实现类
//			FileItemFactory fileItemFactory = new DiskFileItemFactory();
//			// 创建用于解析上传数据的工具类ServletFileUpload类
//			ServletFileUpload servletFileUpload = new ServletFileUpload(
//					fileItemFactory);
//			try {
//				// 解析上传的数据，得到每一个表单项FileItem
//				List<FileItem> list = servletFileUpload.parseRequest(req);
//				// 循环判断，每一个表单项，是普通类型，还是上传的文件
//				for (FileItem fileItem : list) {
//					if (fileItem.isFormField()) {
//						if (fileItem.getFieldName().equals("username")) {
//							username = fileItem.getString("UTF-8");
//						} else if (fileItem.getFieldName()
//								.equals("password")) {
//							password = fileItem.getString("UTF-8");
//						}
//					} else {
//						// 上传的文件
//						// 保存至...
//						imgPath = "img/" + fileItem.getName();
//						fileItem.write(new File("E:/eclipse/workspace/ERPProject_1.0/WebContent/"
//								+ imgPath));
//					}
//				}
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
////		}
////		User user = (User) req.getSession().getAttribute("user");
////		int username = user.getId();
////		if (flag == 1) {
////			resp.sendRedirect(req.getContextPath()
////					+ "/client/clientBookServlet?action=page");
////		} else {
////			req.getRequestDispatcher("/page/client/submitBook.jsp").forward(
////					req, resp);
//		}
//	}
//
//	private boolean isMultipartContent(HttpServletRequest req) {
//		if (!"post".equals(req.getMethod().toLowerCase())) {
//            return false;
//        } else {
//            String contentType = req.getContentType();
//            if (contentType == null) {
//                return false;
//            } else {
//                return contentType.toLowerCase().startsWith("multipart/");
//            }
//        }
//
//	}
//}